import { createStore } from 'vuex'
import { getMusicLyric } from '@/components/request/api/item.js'
import { getPhoneLogin } from '../components/request/api/home'
export default createStore({
  //state存放数据，通过mapState解构
  //state里面的数据在使用的时候，一般是挂在computed里面的，因为如果你挂在data上面，只会赋值一次，不会跟着vuex里面的变化而同步变化
  //当然也可以通过watch $store去解决这个问题
  //接着再说mapState，作用就是可以在computed里面少写一些代码
  state: {
    playList: [{ //播放列表
      al: {
        id: 89039055,
        name: "雨爱抖音版",
        pic: 109951164966568500,
        picUrl: "https://p1.music.126.net/2f6UgY8Jc0Dy6jufMdIZeQ==/109951164966568495.jpg",
        pic_str: "109951164966568495"
      },
      id: 1446137141,
      name: "雨爱（抖音版）",
      ar: [{ name: "灏灏灏仔" }]
    }],
    playListIndex: 0,//默认下标为0
    isbtnShow: true,//播放按钮的显示
    detailShow: false,//歌曲详情页的显示
    lyricList: {},//歌词
    currentTime: 0,//歌曲当前时间
    duration: 0,//歌曲总时长
    isLogin: false,//判断是否登录
    isFooterMusic: true,//判断底部组件是哦福需要显示
  },
  //mutations存放方法，用来操作state中的数据，通过mapMutations解构
  mutations: {
    updateIsbtnShow(state, value) {
      state.isbtnShow = value
    },
    pushPlayList(state, value) {
      state.playList.push(value)
    },
    updatePlayList(state, value) {
      state.playList = value;
      console.log(state.playList);
    },
    updatePlayListIndex(state, value) {
      state.playListIndex = value;

    },
    updateDetailShow(state) {
      state.detailShow = !state.detailShow
    },
    updateLyricList(state, value) {
      state.lyricList = value
    },
    updateCurrentTime(state, value) {
      // console.log(state.currentTime)
      state.currentTime = value;
    },
    //更新歌曲总时长
    updateDuration(state, value) {
      state.duration = value;
      console.log(state.duration);
    },
    //更新登录状态
    updateIsLogin(state, value) {
      state.isLogin = value;
    }
  },
  actions: {
    async getLyric(context, value) {
      let res = await getMusicLyric(value)
      //console.log(res);
      context.commit('updateLyricList', res.data.lrc)
    },
    async getLogin(context, value) {
      let res = await getPhoneLogin(value);
      // console.log(res)
      return res
    }
  },
  modules: {
  }
})
